package com.yehongyu.mytools.ui.swing;

//: Tabbed.java
//Using tabbed panes
import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;

public class Tabbed extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static Object[][] q = { { "Felix", Borders.class },
			{ "The Professor", Buttons.class },
			{ "Rock Bottom", ButtonGroups.class }, { "Theodore", Faces.class },
			{ "Simon", Menus.class }, { "Alvin", Popup.class },
			{ "Tom", ListCombo.class }, { "Jerry", Progress.class },
			{ "Bugs", Trees.class }, { "Daffy", Table.class }, };

	static JPanel makePanel(Class<?> c) {
		String title = c.getName();
		title = title.substring(title.lastIndexOf('.') + 1);
		JPanel sp = null;
		try {
			sp = (JPanel) c.newInstance();
		} catch (Exception e) {
			System.out.println(e);
		}
		sp.setBorder(new TitledBorder(title));
		return sp;
	}

	public Tabbed() {
		setLayout(new BorderLayout());
		JTabbedPane tabbed = new JTabbedPane();
		for (int i = 0; i < q.length; i++)
			tabbed.addTab((String) q[i][0], makePanel((Class<?>) q[i][1]));
		add(tabbed, BorderLayout.CENTER);
		tabbed.setSelectedIndex(q.length / 2);
	}

	public static void main(String args[]) {
		Show.inFrame(new Tabbed(), 460, 350);
	}
} // /:~
